package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
//@Aspect


public class MyAspect1 {
    @Pointcut("execution(* com.itheima.Controller.DeptController.*(..))")
    private void pt() {
    }

    //前置通知
    @Before("pt()")
    public void before(JoinPoint joinPoint) {
        log.info("before ...");

    }

    //环绕通知
    @Around("pt()")
    public Object around(ProceedingJoinPoint pjd) throws Throwable {
        log.info("around...before");
        Object proceed = pjd.proceed();
        log.info("around...after");
        return proceed;
    }


    //后置通知
    @After("pt()")
    public void after(JoinPoint joinPoint) {
        log.info("after...");
    }

    //返回后通知（程序在正常执行的情况下，会执行的后置通知）
    @AfterReturning("pt()")
    public void afterReturning(JoinPoint joinPoint) {
        log.info("afterReturning...");
    }

    //异常后通知（程序在出现异常的情况下，会执行的后置通知）
    @AfterThrowing("pt()")
    public void afterThrowing(JoinPoint joinPoint) {
        log.info("afterThrowing...");
    }
}
